package com.atguigu.config;

import java.beans.PropertyVetoException;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import com.alibaba.druid.pool.DruidDataSource;
import com.mchange.v2.c3p0.ComboPooledDataSource;

@Configuration
@PropertySource(value = { "classpath:database.properties" })
public class DatasourceConfig {
	@Value("${database.connection.url}")
	private String driver;
//	@Bean
//	public DataSource dataSource(){
//		ComboPooledDataSource dataSource =new ComboPooledDataSource();
//		try {
//			dataSource.setDriverClass(driver);
//			dataSource.setJdbcUrl("jdbc:oracle:thin:@192.168.20.151:1521:nari");
//			dataSource.setUser("jlpx");
//			dataSource.setPassword("jlpx");			
//			dataSource.setMinPoolSize(2);
//			dataSource.setMaxPoolSize(20);
//			dataSource.setMaxIdleTime(1800);
//			dataSource.setAcquireIncrement(2);
//			dataSource.setMaxStatements(100);
//			dataSource.setInitialPoolSize(3);
//			dataSource.setIdleConnectionTestPeriod(1800);
//			dataSource.setAcquireRetryAttempts(4);
//			dataSource.setBreakAfterAcquireFailure(true);
//			dataSource.setTestConnectionOnCheckout(false);
//		} catch (PropertyVetoException e) {			
//			e.printStackTrace();
//		}
//		return dataSource;
//	}
	
	@Bean
	public DataSource dataSource(){
		DruidDataSource dataSource =new DruidDataSource();//c3p0
		dataSource.setDriverClassName("oracle.jdbc.driver.OracleDriver");
		dataSource.setUrl("jdbc:oracle:thin:@127.0.0.1:1521:orcl");			
		dataSource.setUsername("scott");
		dataSource.setPassword("123456");		
		return dataSource;
	}
}
